package vo

import (
	"github.com/spf13/cast"
	"honghu_be/dal/po"
)

type AdVo struct {
	AdId        string `json:"ad_id"`
	Image       string `json:"image"`       // 图片
	Uni         string `json:"uni"`         // 大学名称
	UniEn       string `json:"uni_en"`      // 大学英文名称
	Description string `json:"description"` // 描述, 如"录取XX人"
	Count       int    `json:"count"`       // 人数
}

func (a *AdVo) ToPo() *po.Ad {
	return &po.Ad{
		Image:       a.Image,
		Uni:         a.Uni,
		UniEn:       a.UniEn,
		Description: a.Description,
		Count:       a.Count,
	}
}

func ToAdVo(ad *po.Ad) *AdVo {
	return &AdVo{
		AdId:        cast.ToString(ad.Model.ID),
		Image:       ad.Image,
		Uni:         ad.Uni,
		UniEn:       ad.UniEn,
		Description: ad.Description,
		Count:       ad.Count,
	}
}

func ToAdVos(ads []*po.Ad) []*AdVo {
	ret := make([]*AdVo, len(ads))
	for i := range ads {
		ret[i] = ToAdVo(ads[i])
	}
	return ret
}
